import config from "./config.js"


function getToken(){
    return new Promise((resolve,reject)=>{
        wx.getStorage({
            key: 'token',
            success: res=>{
               resolve(res.data)
            },
            fail:err=>{
                resolve("111")
               console.log(err)
            }
        
        })
    })
}


export  function requestUpload(url,method,data,flg){
    // let token=await getToken()
    return new Promise((resolve,reject)=>{
       if(!flg){
        wx.showLoading({
            title:"加载中...",
            duration:600
        })
       }
       
        getToken().then(token=>{      
            wx.uploadFile({
              url: config.baseUrl + url,
              filePath: data,
              name: "image", //name should be the file key in formData,
              header: {
                token:token||"111",
                "content-Type":"multipart/form-data"
              },
              method: 'POST',
              formData: {
              },
              success: res => {
                  resolve(res);
                //   console.log(res)
              },
              fail: err => {
                  wx.showToast({
                      icon:"none",
                      title:"网络错误"
                  })
              },
             
              complete: function () {
   
              }         
             })
        })  
    }) 
} 